#!/usr/bin/env python3
"""
博客项目测试运行器
"""

import unittest
import sys
import os

# 添加当前目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

# 运行测试
if __name__ == '__main__':
    # 创建测试套件
    loader = unittest.TestLoader()
    suite = loader.discover('.', pattern='test_*.py')
    
    # 运行测试
    runner = unittest.TextTestRunner(verbosity=2)
    result = runner.run(suite)
    
    # 统计结果
    print("\n" + "="*60)
    print("测试完成！")
    print("="*60)
    print("运行测试: {}".format(result.testsRun))
    print("成功: {}".format(result.testsRun - len(result.failures) - len(result.errors)))
    print("失败: {}".format(len(result.failures)))
    print("错误: {}".format(len(result.errors)))
    
    if result.failures:
        print("\n失败详情:")
        for test, traceback in result.failures:
            print("- {}: {}".format(test, traceback))
    
    if result.errors:
        print("\n错误详情:")
        for test, traceback in result.errors:
            print("- {}: {}".format(test, traceback))
    
    # 返回退出码
    sys.exit(0 if result.wasSuccessful() else 1)
